<?php
/**
 * store configuration setting
 */
class store_config extends CI_Controller{
	/**
	 * load default models and save them to $this without model suffix
	 */
	public function __construct()
	{
		parent::__construct();
		$this->load->model('store_model', 'store');
  }
	/**
	 * load store information and displays it 
	 */
	public function index()
	{
		$store = $this->store->get_store_info();
		$data = array(
					'page_title' => 'store configuration',
					'page_css'   => array('admin.css'),
					'page_js'    => array(),
					'store'     => $store
					);
					
		$this->load->view('admin/store_config', $data);
	}
	
	/**
	 * update store information
	 *
	 * @return JSON
	 */
	public function update()
	{
        $result = $this->store->update_store_info(
            $this->input->post('phone'), $this->input->post('name'),
            $this->input->post('address'), $this->input->post('city'),
            $this->input->post('state'), $this->input->post('zipcode'),
            $this->input->post('footer'), $this->input->post('taxrate')
        );

        if($this->input->is_ajax_request()){
            $message = "";
            if(count($result['user']) === 0){
                $status = "good";
            }
            else{
                $status = "fail";
                foreach($result['user'] as $value){
                    $message .= $value . "\n\n";
                }
            }
            /** send message back to AJAX client */
            $msg = json_encode(array('status' => $status , 'error' => $message));
            echo $msg;
        }
        else{
            //no post method yet
        }
	}
}

/* End of file store_config.php */
/* Location: ./system/application/controllers/admin/store_config.php */
